package exception03;

public class Person {
    private int age;

    public Person(int age)throws AgeException {
        if (age < 0) {
            /**
             * 当年龄<0时候,我们考虑抛出一个异常对象,提示调用者
             * 但是为了让这个异常对象见名知意,所以不抛Exception对象
             * throw new 年龄异常();
             */
            //throw new AgeException();
            throw new AgeException("年龄不能为" + age);
        }
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age)throws AgeException {
        if (age < 0) {
            throw new AgeException();
        }
        this.age = age;
    }
}
